package kr.or.javacafe.magic;

public class FourMagicSquare extends AbstractMagicSquare {
	public FourMagicSquare(){
		this(4);
	}
	
	public FourMagicSquare(int n){
		super.init(n);
	}

	public void make(){
		makeRight();
		makeLeft();
	}
	
	public void makeRight(){
		int count = top+1;
		for (int i = 0; i < magic.length; i++) {
			for (int j = 0; j < magic[i].length; j++) {
				magic[i][j]=i*count+j+1;
			}
		}
	}
	public void makeLeft(){
		int count = top+1;
		for (int i = 0; i < magic.length; i++) {
			for (int j = 0; j < magic[i].length; j++) {
				if ( (i>=0&& i<count/4) || (i>=count/4*3 && i<count) ) {
					if (j>=count/4 && j<count/4*3) {
						magic[i][j]= (count*count)-(i*count+j);
					}
				}else{
					if ( (j>=0&& j<count/4) || (j>=count/4*3 && j<count) ) {
						magic[i][j]= (count*count)-(i*count+j);
					}
				}
			}
		}		
	}
}



















